home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_multibytecodec.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  3KB  |  78 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. from test import test_support
  5. from test import test_multibytecodec_support
  6. import unittest
  7. import StringIO
  8. import codecs
  9.  
  10. class Test_StreamWriter(unittest.TestCase):
  11.     if len(u'\xf0\x92\x8d\x85') == 2:
  12.         
  13.         def test_gb18030(self):
  14.             s = StringIO.StringIO()
  15.             c = codecs.lookup('gb18030')[3](s)
  16.             c.write(u'123')
  17.             self.assertEqual(s.getvalue(), '123')
  18.             c.write(u'\xf0\x92\x8d\x85')
  19.             self.assertEqual(s.getvalue(), '123\x907\x959')
  20.             c.write(u'\xf0\x92\x8d\x85'[0])
  21.             self.assertEqual(s.getvalue(), '123\x907\x959')
  22.             c.write(u'\xf0\x92\x8d\x85'[1] + u'\xf0\x92\x8d\x85' + u'\xea\xb0\x80\xc2\xac')
  23.             self.assertEqual(s.getvalue(), '123\x907\x959\x907\x959\x907\x959\x827\xcf5\x810\x851')
  24.             c.write(u'\xf0\x92\x8d\x85'[0])
  25.             self.assertEqual(s.getvalue(), '123\x907\x959\x907\x959\x907\x959\x827\xcf5\x810\x851')
  26.             self.assertRaises(UnicodeError, c.reset)
  27.             self.assertEqual(s.getvalue(), '123\x907\x959\x907\x959\x907\x959\x827\xcf5\x810\x851')
  28.  
  29.         if test_multibytecodec_support.__cjkcodecs__:
  30.             
  31.             def test_utf_8(self):
  32.                 s = StringIO.StringIO()
  33.                 c = codecs.lookup('utf-8')[3](s)
  34.                 c.write(u'123')
  35.                 self.assertEqual(s.getvalue(), '123')
  36.                 c.write(u'\xf0\x92\x8d\x85')
  37.                 self.assertEqual(s.getvalue(), '123\xf0\x92\x8d\x85')
  38.                 c.write(u'\xf0\x92\x8d\x85'[0])
  39.                 self.assertEqual(s.getvalue(), '123\xf0\x92\x8d\x85')
  40.                 c.write(u'\xf0\x92\x8d\x85'[1] + u'\xf0\x92\x8d\x85' + u'\xea\xb0\x80\xc2\xac')
  41.                 self.assertEqual(s.getvalue(), '123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xea\xb0\x80\xc2\xac')
  42.                 c.write(u'\xf0\x92\x8d\x85'[0])
  43.                 self.assertEqual(s.getvalue(), '123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xea\xb0\x80\xc2\xac')
  44.                 c.reset()
  45.                 self.assertEqual(s.getvalue(), '123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xea\xb0\x80\xc2\xac\xed\xa0\x88')
  46.                 c.write(u'\xf0\x92\x8d\x85'[1])
  47.                 self.assertEqual(s.getvalue(), '123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xea\xb0\x80\xc2\xac\xed\xa0\x88\xed\xbd\x85')
  48.  
  49.         
  50.     
  51.     
  52.     def test_nullcoding(self):
  53.         self.assertEqual(''.decode('gb18030'), u'')
  54.         self.assertEqual(unicode('', 'gb18030'), u'')
  55.         self.assertEqual(u''.encode('gb18030'), '')
  56.  
  57.     
  58.     def test_str_decode(self):
  59.         self.assertEqual('abcd'.encode('gb18030'), 'abcd')
  60.  
  61.     
  62.     def test_streamwriter_strwrite(self):
  63.         s = StringIO.StringIO()
  64.         wr = codecs.getwriter('gb18030')(s)
  65.         wr.write('abcd')
  66.         self.assertEqual(s.getvalue(), 'abcd')
  67.  
  68.  
  69.  
  70. def test_main():
  71.     suite = unittest.TestSuite()
  72.     suite.addTest(unittest.makeSuite(Test_StreamWriter))
  73.     test_support.run_suite(suite)
  74.  
  75. if __name__ == '__main__':
  76.     test_main()
  77.  
  78.